using System;
using System.Windows;
using MinoChat.Ui.Enums;

namespace MinoChat.Ui;

/// 主题资源字典，根据传入的 ThemeMode 枚举值自动构建 Pack URI 路径并加载对应的主题资源
/// 仅支持实际视觉主题（Light/Dark/HighContrast），不包含 Auto 逻辑
/// </summary>
public class ThemesDictionary : ResourceDictionary
{
    private ThemeMode _themeMode = ThemeMode.Light;

    /// <summary>
    /// 主题类型
    /// </summary>
    public ThemeMode ThemeMode
    {
        get => _themeMode;
        set
        {
            _themeMode = value;
            UpdateSource();
        }
    }

    /// <summary>
    /// 构造函数，默认使用浅色主题
    /// </summary>
    public ThemesDictionary()
    {
        UpdateSource();
    }

    /// <summary>
    /// 根据当前主题值更新资源字典的 Source 属性
    /// </summary>
    private void UpdateSource()
    {
        var themeName = _themeMode switch
        {
            ThemeMode.Light => "LightTheme",
            ThemeMode.Dark => "DarkTheme",
            ThemeMode.HighContrast => "HighContrastTheme",
            _ => "LightTheme"
        };

        var uri = new Uri($"/MinoChat.Ui;component/Resources/Themes/{themeName}.xaml", UriKind.Relative);
        Source = uri;
    }
}
